<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>机构管理页面</title>
<%@ include file="../include/easyui.jsp"%>
</head>
<body style="font-family: '微软雅黑'">
<div id="toolbar" style="padding:5px;height:auto">
    <div>
        <shiro:hasPermission name="system:organization:add">
            <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-add" onclick="add();">添加</a>
            <span class="toolbar-item dialog-tool-separator"></span>
        </shiro:hasPermission>
        <shiro:hasPermission name="system:organization:delete">
            <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-remove" onclick="del()">删除</a>
            <span class="toolbar-item dialog-tool-separator"></span>
        </shiro:hasPermission>
        <shiro:hasPermission name="system:organization:update">
            <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-edit" onclick="update()">修改</a>
        </shiro:hasPermission>
    </div>
</div>
<table id="dg"></table>
<div id="dlg"></div>

<script type="text/javascript">
var dg;
var dialog;
var pid;
$(function(){
	dg=$('#dg').treegrid({
        method: "get",
        url:'${ctx}/system/organization/list',
        fit : true,
        fitColumns : true,
        border : false,
        idField : 'id',
        treeField:'name',
        parentField : 'parentId',
        iconCls: 'icon',
        animate:true,
        rownumbers:false,
        singleSelect:true,
        striped:true,
        columns:[[
            {field:'id',title:'id',hidden:true,width:100},
            {field:'name',title:'机构名称',width:100},
            {field:'code',title:'机构编码',width:100},
            {field:'sort',title:'排序', width:100},
            {field:'updateTime',title:'更新时间',sortable:true,width:130,formatter:formatterdateAll},
        ]],
        enableHeaderClickMenu: false,
        enableHeaderContextMenu: false,
        enableRowContextMenu: false,
        toolbar:'#toolbar',
        dataPlain: true
	});
});

//弹窗增加
function add() {
	//父级权限
	var row = dg.treegrid('getSelected');
	if(row){
		pid = row.id;
	}

    dialog=$('#dlg').dialog({
	    title: '添加机构',    
	    width: 450,    
	    height: 320,    
	    closed: false,    
	    cache: false,
	    maximizable:true,
	    resizable:true,
	    href:'${ctx}/system/organization/addForm',
	    modal: true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
                dialog.panel('close');
            }
		}]
	});
}

//删除
function del(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) {
	    return;
	}
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/system/organization/delete/"+row.id,
				success: function(data){
					if(successTip(data.message,dg)) {
                        dg.treegrid('reload');
                    }
				}
			});
		} 
	});
}

//修改
function update(){
	var row = dg.treegrid('getSelected');
	if(rowIsNull(row)) {
	    return;
	}
	//父级权限
	pid = row.parentId;
    dialog=$("#dlg").dialog({
	    title: '修改机构',    
	    width: 450,    
	    height: 320,    
	    href:'${ctx}/system/organization/updateForm/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit();
			}
		},{
			text:'取消',
			handler:function(){
                dialog.panel('close');
            }
		}]
	});
}
</script>
</body>
</html>